package com.lonwin.inspectionmanagement.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.astuetz.PagerSlidingTabStrip;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.lonwin.inspectionmanagement.R;
import com.lonwin.inspectionmanagement.R2;
import com.lonwin.inspectionmanagement.di.component.DaggerNewCruiseRecordComponent;
import com.lonwin.inspectionmanagement.mvp.contract.NewCruiseRecordContract;
import com.lonwin.inspectionmanagement.mvp.presenter.NewCruiseRecordPresenter;
import com.lonwin.inspectionmanagement.mvp.ui.adapter.NewCruiseRecordTabAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 12/15/2018 11:22
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class NewCruiseRecordActivity extends BaseActivity<NewCruiseRecordPresenter> implements NewCruiseRecordContract.View {

    @BindView(R2.id.back_icon)
    ImageView backIcon;
    @BindView(R2.id.toolbar_back)
    RelativeLayout toolbarBack;
    @BindView(R2.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R2.id.back_right_icon)
    TextView backRightIcon;
    @BindView(R2.id.toolbar_right)
    RelativeLayout toolbarRight;
    @BindView(R2.id.toolbar)
    Toolbar toolbar;
    @BindView(R2.id.vehicle_violation_tabs)
    PagerSlidingTabStrip vehicleViolationTabs;
    @BindView(R2.id.vehicle_violation_info_viewPager)
    ViewPager vehicleViolationInfoViewPager;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerNewCruiseRecordComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_new_cruise_record; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        vehicleViolationInfoViewPager.setAdapter(new NewCruiseRecordTabAdapter(getSupportFragmentManager(),this));
        vehicleViolationTabs.setViewPager(vehicleViolationInfoViewPager);
        final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
                .getDisplayMetrics());
        vehicleViolationInfoViewPager.setPageMargin(pageMargin);
        vehicleViolationInfoViewPager.setCurrentItem(0);
         setonClick();
    }
    public void setonClick(){
        toolbarRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(NewCruiseRecordActivity.this, CruiseSearchActivity.class);
             startActivityForResult(intent,1001);
            }
        });
        vehicleViolationTabs.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
            @Override
            public void onTabReselected(int position) {
                Log.i("###", "onTabReselected:" + position);
                //tab点击选中


            }
        });
        vehicleViolationTabs.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                Log.i("###", "onPageSelected:" + position);
                //tab滑动选中


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
